var ajaxUrl = "http://9sd6qf.natappfree.cc/teacher";
$.ajax({
	url: ajaxUrl + "/api/get_pro",
	type: 'GET',
	async: false,
	jsonpCallback: "success_jsonpCallback",
	success: function(result) {
		province = result;
	},
	error: function(xhr, status, error) {}
});

var areaContent, expressArea;

function Province() {
	$(".province").html("请选择");
	areaContent = "";
	for(var i = 0; i < province.length; i++) {
		areaContent += '<li onClick="selectProvince(' + province[i].pcdId + ',' + i + ');">' + province[i].pcdName + '</li>';
	}
	$(".selectKindergartenBox").html(areaContent);
}
Province();

function selectProvince(p, i) {
	areaContent = "";
	$(".selectKindergartenBox").html("");
	$(".kindergarten").html("")
	$.ajax({
		url: ajaxUrl + "/api/get_city",
		type: 'GET',
		data: {
			'pro_id': p
		},
		async: false,
		jsonpCallback: "success_jsonpCallback",
		success: function(result) {
			city = result;
			for(var j = 0; j < city.length; j++) {
				areaContent += '<li onClick="selectCity(' + p + ',' + city[j].pcdId + ',' + j + ');">' + city[j].pcdName + '</li>';
			}
			$(".selectKindergartenBox").html(areaContent);
			expressArea = province[i];
			$(".province").html(expressArea.pcdName);
			$(".city").html("请选择")
		},
		error: function(xhr, status, error) {}
	});
}

function selectCity(p, c, j) {
	var areaContent = "";
	$(".selectKindergartenBox").html("");
	$.ajax({
		url: ajaxUrl + "/api/get_base_park?pcdCoce=" + c,
		type: 'post',
		data: {
			'pcdCode': c
		},
		async: false,
		jsonpCallback: "success_jsonpCallback",
		success: function(result) {
			district = result;
			for(var k = 0; k < district.length; k++) {
				var s = "'" + district[k].schCode + "'";
				var f = "'" + district[k].schName + "'";
				areaContent += '<li onClick="selectDT(' + p + ',' + c + ',' + s + ',' + f + ')">' + district[k].schName + '</li>';
			}
			$(".selectKindergartenBox").html(areaContent);
			city = city[j];
			$(".city").html(city.pcdName);
			$(".kindergarten").html("请选择")
			var sCity = city[c];
			if(sCity != "省直辖县级行政单位") {
				if(sCity == "东莞市" || sCity == "中山市" || sCity == "儋州市" || sCity == "嘉峪关市") {
					expressArea += sCity;
					$("#expressArea dl").html(expressArea);
					clockArea();
				} else if(sCity == "市辖区" || sCity == "市辖县" || sCity == "香港岛" || sCity == "九龙半岛" || sCity == "新界" || sCity == "澳门半岛" || sCity == "离岛" || sCity == "无堂区划分区域") {
					expressArea += "";
				} else {
					expressArea += sCity + " > ";
				}
			}
		},
		error: function(xhr, status, error) {}
	});
}

/*选择区县*/
function selectDT(p, c, d, f) {
	expressArea = f;
	var i = expressArea.lastIndexOf('>');
	var B = expressArea.substr(i + 1, 20);
	$(".kindergarten").html(B); //新增的
	$("#selectKindergarten").attr('value', f);
	closeSelectKindergarten();
}

function openSelectKindergarten() {
	$(".mask").fadeIn();
	$(".selectKindergarten").animate({
		"bottom": 0
	});
}


function closeSelectKindergarten() {
	$(".mask").fadeOut();
	$(".selectKindergarten").animate({
		"bottom": "-100%"
	});
}

$(".province").click(function() {
	Province()
})

